package com.gxa.admin.recycling.service.impl;


import com.gxa.admin.recycling.mapper.UserMapper;
import com.gxa.admin.recycling.service.UserService;
import com.gxa.core.recycling.pojo.User;
import com.gxa.core.recycling.service.impl.BaseServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("userService")
@Transactional(rollbackFor = {Throwable.class})
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public Map<Integer,List<Map>> findUserByPage(Long uid, String phone, String username,String provinces, Long cid, Integer page, Integer size) {
        Map<Integer,List<Map>> map=new HashMap<>();

        if (phone!=null && phone !=""){
            phone = "%"+phone+"%";
        }
        if (username!=null && username !=""){
            username = "%"+username+"%";
        }
        if (provinces!=null && provinces !=""){
            provinces = "%"+provinces+"%";
        }

        List<Map> data = userMapper.findUserByPage(uid, phone, username,provinces, cid, (page-1)*size, size);
        Integer total = userMapper.findUserByPage(uid, phone, username,provinces, cid, null, null).size();

        map.put(total,data);
        return map;
    }

    @Override
    public Map findUserById(Long id) {
        return userMapper.findUserById(id);
    }
}
